package com.uni.tag_group.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.uni.tag_group.R;
import com.uni.tag_group.databinding.ActivityTagWordwrapBinding;
import com.uni.taggroupview.TagView;

import java.util.Random;

public class TagWordWrapActivity extends AppCompatActivity {
    ActivityTagWordwrapBinding binding;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= DataBindingUtil.setContentView(this, R.layout.activity_tag_wordwrap);

        binding.etView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if(s !=null && s.length()>0 && s.length()<5){
                    int r=Integer.valueOf(s.toString());
                    binding.tagView.setRoundedCorners(r);
                    binding.tagView.refresh();

                    binding.tagView1.setRoundedCorners(r);
                    binding.tagView1.refresh();

                    binding.tagView2.setRoundedCorners(r);
                    binding.tagView2.refresh();
                }
            }
        });
        // 设置点击回调
        binding.tagView.setClickCallback((view, index) -> {
            Log.e("TAG", "onClick: "+index);
        });
        // 设置长按回调
        binding.tagView.setLongClickCallback((view, index) -> {
            Log.e("TAG", "onLongClick: "+index);
            return false;
        });
        int[] color=new int[]{Color.parseColor("#ee82ee")};
        int[] color2=new int[]{Color.parseColor("#3a4143")};

        binding.tagView1.setTagLeftBgColor(color);
        binding.tagView1.setTagRightBgColor(color2);

        binding.tagView2.setTagLeftBgColor(color);
        binding.tagView2.setTagRightBgColor(color2);
    }


    public void clickView(View view){
        switch (view.getId()) {
            case R.id.btn1:
                Random random = new Random();
                int randomColor= Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
                binding.tagView.setBgColor(randomColor);
                binding.tagView.refresh();
                break;
            case R.id.btn2:
                binding.tagView.setRounded(!binding.tagView.isRounded());
                binding.tagView.refresh();
                if(!binding.tagView.isRounded()){
                    binding.etView.setVisibility(View.VISIBLE);
                }else {
                    binding.etView.setVisibility(View.GONE);
                }
                break;
            case R.id.btn3:
                binding.tagView.setHollowOut(!binding.tagView.isHollowOut());
                binding.tagView.refresh();
                break;
            case R.id.btn4:
                binding.tagView.setSideMode(TagView.SizeMode.SMALL);
                binding.tagView.refresh();

                binding.tagView1.setSideMode(TagView.SizeMode.SMALL);
                binding.tagView1.refresh();

                binding.tagView2.setSideMode(TagView.SizeMode.SMALL);
                binding.tagView2.refresh();
                break;
            case R.id.btn5:
                binding.tagView.setSideMode(TagView.SizeMode.GENERAL);
                binding.tagView.refresh();

                binding.tagView1.setSideMode(TagView.SizeMode.GENERAL);
                binding.tagView1.refresh();

                binding.tagView2.setSideMode(TagView.SizeMode.GENERAL);
                binding.tagView2.refresh();
                break;
            case R.id.btn6:
                binding.tagView.setSideMode(TagView.SizeMode.LARGE);
                binding.tagView.refresh();

                binding.tagView1.setSideMode(TagView.SizeMode.LARGE);
                binding.tagView1.refresh();

                binding.tagView2.setSideMode(TagView.SizeMode.LARGE);
                binding.tagView2.refresh();
                break;
        }
    }
}
